Import diddy
Import globals

Class HamSimpleMenu Extends SimpleMenu

	Field HamList:=New List<HamSimpleButton>

	Method New(soundMouseOverFile$, soundClickFile$, x:Int, y:Int, gap:Int, useVirtualRes:Bool, orientation:Int = VERTICAL)
		Init(soundMouseOverFile, soundClickFile, x, y, gap, useVirtualRes, orientation)
	End

	Method AddHButton:HamSimpleButton(buttonImage:GameImage, mouseOver:GameImage, name:String="")
		Local b:HamSimpleButton = ProcessHAddButton(buttonImage, mouseOver, name)
		If orientation = VERTICAL
			IncreaseHeight(b)
		Else
			IncreaseWidth(b)
		End
		Return b
	End


	Method ProcessHAddButton:HamSimpleButton(buttonImage:GameImage, mouseOver:GameImage, name:String)
		Local b:HamSimpleButton = New HamSimpleButton
		b.HLoad(buttonImage, mouseOver)
		b.useVirtualRes = Self.useVirtualRes
		b.orientation = Self.orientation
		If name <> "" Then b.name = name.ToUpper
		
		If orientation = VERTICAL
			b.CentreX(nextY)
		Else
			b.MoveTo(nextX, nextY)
		End
		
		b.soundMouseOver = soundMouseOver 
		b.soundClick = soundClick 
		AddLast(b)'HamList.
		Return b
	End


	Method Update:Int()
		If diddyGame.screenFade.active
			Return 0
		EndIf
		clickedName = ""
		Local b:SimpleButton
		For b = Eachin Self
			b.Update()
			If b.mouseOver Then 
				mouseOverName = b.name
				'Print "Over: "+mouseOverName
			Endif
			If b.clicked Then 
				clickedName = b.name	
				'Print "Clicked: "+clickedName
			Endif
		Next
		Return 1
	End

End

Class HamSimpleTextMenu Extends SimpleMenu

	Method New(soundMouseOverFile$, soundClickFile$, x:Int, y:Int, gap:Int, useVirtualRes:Bool, orientation:Int = VERTICAL)
		Init(soundMouseOverFile, soundClickFile, x, y, gap, useVirtualRes, orientation)
	End

	Method AddHTButton:HamSimpleTextButton(buttontext:String,name:String="")
		Local b:HamSimpleTextButton = ProcessHTAddButton(buttontext,name)
		If orientation = VERTICAL
			HIncreaseHeight(b)
		Else
			HIncreaseWidth(b)
		End
		Return b
	End
	
	Method ProcessHTAddButton:HamSimpleTextButton(buttontext:String, name:String)
		Local b:HamSimpleTextButton = New HamSimpleTextButton		
		b.HLoad(buttontext)
		b.useVirtualRes = Self.useVirtualRes
		b.orientation = Self.orientation
		If name <> "" Then b.name = name.ToUpper
		
		If orientation = VERTICAL
			b.HCentreX(nextY)
		Else
			b.MoveTo(nextX, nextY)
		End
		
		b.soundMouseOver = soundMouseOver 
		b.soundClick = soundClick 
		AddLast(b)'HamList.
		Return b
	End

	Method HIncreaseHeight:Void(b:HamSimpleTextButton)
		nextY = nextY + MainFont.TextHeight(b.buttonstring) + 3

		h = h + MainFont.TextHeight(b.buttonstring)
		If addGap Then
			h = h + 1
		Else
			addGap = 1
		End			
	End

	Method HIncreaseWidth:Void(b:HamSimpleTextButton)
		nextX = nextX + MainFont.TextWidth(b.buttonstring) + buttonGap

		w = w + MainFont.TextWidth(b.buttonstring)
		If addGap Then
			w = w + buttonGap
		Else
			addGap = 1
		End
	End
	
End

Class HamSimpleTextButton Extends SimpleButton

	Field buttonstring:String

	Method HLoad:Void(buttontext:String, soundMouseOverFile:String="", soundClickFile:String="",nname:String="")
		Local hi:HGameImage = New HGameImage
		hi.HLoad(CreateImage(MainFont.TextWidth(buttonstring),MainFont.TextWidth(buttonstring)),nname,True,True,0,0,0,False)
		Self.image = hi
		'image.Load(diddyGame.images.path + buttonImage, False)
		
		'if  mouseOverImage <> null
		'	imageMouseOver = mouseOverImage
			'imageMouseOver.Load(diddyGame.images.path + mouseOverImage, False)
		'End
		buttonstring = buttontext
		name = nname
		
		If soundMouseOverFile<>"" Then
			soundMouseOver = New GameSound
			soundMouseOver.Load(soundMouseOverFile)
		End
		If soundClickFile<>"" Then
			soundClick = New GameSound
			soundClick.Load(soundClickFile)
		End
	End

	Method HCentreX:Void(yCoord:Int)
		if useVirtualRes
			MoveTo((SCREEN_WIDTH-MainFont.TextWidth(buttonstring))/2, yCoord)
		Else
			MoveTo((DEVICE_WIDTH-MainFont.TextWidth(buttonstring))/2, yCoord)
		End
		
	End
	
	Method HCentreY:Void(xCoord:Int)
		If useVirtualRes
			MoveTo((SCREEN_HEIGHT-MainFont.TextHeight(buttonstring))/2, xCoord)
		Else
			MoveTo((DEVICE_HEIGHT-MainFont.TextHeight(buttonstring))/2, xCoord)
		End
	End

	
	Method Update:Void()
		If active = 0 or disabled Then Return
		Local mx:Int = diddyGame.mouseX
		Local my:Int = diddyGame.mouseY
		if not useVirtualRes
			mx = MouseX()
			my = MouseY()
		End
		Local ix:Int = x-(MainFont.TextWidth(buttonstring)/2)
		Local iy:Int = y-(MainFont.TextHeight(buttonstring)/2)
		
		If mx >= ix And mx < ix+MainFont.TextWidth(buttonstring) And my >= iy And my < iy+MainFont.TextHeight(buttonstring) Then
			If mouseOver = 0
				if soundMouseOver <> null
					soundMouseOver.Play()
				End
			End
			mouseOver = 1
			If MouseHit() Then
				Click()
			Else
				clicked = 0
			End
		Else
			mouseOver = 0	
			clicked = 0
		End
	End


	Method Draw:Void()
		If active = 0 Then Return
		SetAlpha Self.alpha
		Local ix:Int = x-(MainFont.TextWidth(buttonstring)/2)
		Local iy:Int = y-(MainFont.TextHeight(buttonstring)/2)
		If mouseOver

			SetColor(255,255,0)
			MainFont.DrawHTML(buttonstring,ix,iy)
			SetColor(255,255,255)				

		ElseIf selected Then
				SetColor(255,255,0)
				MainFont.DrawHTML(buttonstring,ix,iy)
				SetColor(255,255,255)			
		Else
				SetColor(255,255,255)
				MainFont.DrawHTML(buttonstring,ix,iy)
				SetColor(255,255,255)	
		
		EndIf
		SetAlpha 1
	End	
	

end

Class HamSimpleButton Extends SimpleButton

	Method HLoad:Void(buttonImage:GameImage, mouseOverImage:GameImage, soundMouseOverFile:String="", soundClickFile:String="",nname:String="")
		Self.image = buttonImage
		'image.Load(diddyGame.images.path + buttonImage, False)
		
		if  mouseOverImage <> null
			imageMouseOver = mouseOverImage
			'imageMouseOver.Load(diddyGame.images.path + mouseOverImage, False)
		End
		
		name = nname
		
		If soundMouseOverFile<>"" Then
			soundMouseOver = New GameSound
			soundMouseOver.Load(soundMouseOverFile)
		End
		If soundClickFile<>"" Then
			soundClick = New GameSound
			soundClick.Load(soundClickFile)
		End
	End

	Method Update:Void()
		If active = 0 or disabled Then Return
		Local mx:Int = diddyGame.mouseX
		Local my:Int = diddyGame.mouseY
		if not useVirtualRes
			mx = MouseX()
			my = MouseY()
		End
		Local ix:Int = x-(image.w/2)
		Local iy:Int = y-(image.h/2)
		
		If mx >= ix And mx < ix+image.w And my >= iy And my < iy+image.h Then
			If mouseOver = 0
				if soundMouseOver <> null
					soundMouseOver.Play()
				End
			End
			mouseOver = 1
			If MouseHit() Then
				Click()
			Else
				clicked = 0
			End
		Else
			mouseOver = 0	
			clicked = 0
		End
	End


	Method Draw:Void()
		If active = 0 Then Return
		SetAlpha Self.alpha
		if mouseOver
			if selected And imageSelectedMO <> null Then
				DrawImage Self.imageSelectedMO.image, x, y
				SetColor(255,255,0)
				SetAlpha(0.5)
				DrawRect(x-(Self.imageSelectedMO.image.Width/2),y-(Self.imageSelectedMO.image.Height/2),Self.imageSelectedMO.image.Width,Self.imageSelectedMO.image.Height)
				SetAlpha(1)
				SetColor(255,255,255)
			Else
				DrawImage Self.imageMouseOver.image, x, y
				SetColor(255,255,0)
				SetAlpha(0.5)
				DrawRect(x-(Self.imageMouseOver.image.Width/2),y-(Self.imageMouseOver.image.Height/2),Self.imageMouseOver.image.Width,Self.imageMouseOver.image.Height)
				SetAlpha(1)
				SetColor(255,255,255)				
			End
		ElseIf selected And imageSelected <> null Then
			DrawImage Self.imageSelected.image, x, y
			SetColor(255,255,0)
			SetAlpha(0.5)
			DrawRect(x-(Self.imageSelected.image.Width/2),y-(Self.imageSelected.image.Height),Self.imageSelected.image.Width,Self.imageSelected.image.Height)
			SetAlpha(1)
			SetColor(255,255,255)				
		Else
			SetColor(255,255,255)
			SetAlpha(0.2)
			DrawRect(x-(Self.image.image.Width/2),y-(Self.image.image.Height/2),Self.image.image.Width,Self.image.image.Height)
			SetAlpha(1)
			SetColor(255,255,255)	
			DrawImage Self.image.image, x, y
		
		EndIf
		SetAlpha 1
	End
	
end